package cn.itcast.bos.service.Impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.Impl.UserDaoImpl;
import cn.itcast.bos.dao.base.IUserDao;
import cn.itcast.bos.domain.User;
import cn.itcast.bos.service.IUserService;
import cn.itcast.bos.utils.MD5Utils;

@Service
@Transactional
public class UserServiceImpl implements IUserService{
	@Resource
	private IUserDao userDao;

	@Override
	public User login(User model) {
		String pasword = MD5Utils.md5(model.getPassword());
		List<User> list = userDao.findByNameQuery("findByuserNameAndPassword", model.getUsername(),pasword);
		if (list !=null && list.size()>0) {
			return list.get(0);
		}
		return null;
	}
	
	//修改密码
	public void editPassword(String id, String password) {
		String newpassword = MD5Utils.md5(password);
		userDao.executeNameQuery("editPassword", newpassword,id);
	}

}
